﻿'===================================================================================
'功能說明:管理頁面名稱,querystring 的設定需注意若是同一個URL中的設定需要一致,否則會授權錯誤.2011/3/8目前提供繁中,簡體,英文等3種語文的頁面名稱設定
'建立人員: andy
'建立日期：2011/1/31
''===================================================================================

Partial Class WebForm_Manage_MenuMaintain

    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = UID
            hiActulaUID.Value = ActualUID
            hiDBName.Value = dbName
            '檢查權限'查詢
            If Not ChkProgramRight(1) Then
                gvMenu.Visible = False
            End If
            '新增一筆空白資料
            If Not ChkProgramRight(2) Then
                btnInsert.Visible = False
            End If
            '編輯
            If Not ChkProgramRight(3) Then
                gvMenu.Columns(0).Visible = False
                gvMenuRights.Columns(0).Visible = False
            End If
        End If
    End Sub

    Protected Sub gvMenu_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvMenu.RowUpdating
        '存檔,因為無法抓到相關的值,所以用程式來做
        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        Dim ProgramID As Integer = Integer.Parse(gvMenu.Rows(e.RowIndex).Cells(1).Text)
        Dim RootName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("ddlRootName"), DropDownList).SelectedValue
        Dim Name As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtName"), TextBox).Text
        Dim NeedControl As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbNeedControl"), CheckBox).Checked
        Dim URL As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtURL"), TextBox).Text
        Dim GroupID As String = CType(gvMenu.Rows(e.RowIndex).FindControl("ddlGroupID"), DropDownList).SelectedValue
        Dim QueryStringYN As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbQueryString"), CheckBox).Checked
        Dim ChnName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtChnName"), TextBox).Text
        Dim EngName As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtEngName"), TextBox).Text
        Dim IsMenu As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbIsMenu"), CheckBox).Checked
        Dim IsNewWin As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbIsNewWin"), CheckBox).Checked
        Dim Param As Integer
        Dim MenuType As Integer = Integer.Parse(CType(gvMenu.Rows(e.RowIndex).FindControl("ddlMenuType"), DropDownList).SelectedValue)
        Try
            Param = Integer.Parse(CType(gvMenu.Rows(e.RowIndex).FindControl("txtParam"), TextBox).Text)
        Catch ex As Exception
            Param = 0
        End Try

        Dim IsRoot As Boolean = CType(gvMenu.Rows(e.RowIndex).FindControl("cbIsRoot"), CheckBox).Checked
        Dim OrderByID As String = CType(gvMenu.Rows(e.RowIndex).FindControl("txtOrderByID"), TextBox).Text
        If URL <> "" Then
            If bbl.UrlIsExist(URL, ProgramID, hiDBName.Value) Then
                ShowMessageForAjax(btnClose1, GetLocalResourceObject("URLExist"))
                e.Cancel = True
                Exit Sub
            End If
        End If
        If Name <> "" Then
            If Name.Trim = RootName.Trim Then
                ShowMessageForAjax(btnInsert, GetLocalResourceObject("SameUrlRootName"))
                e.Cancel = True
                Exit Sub
            End If
        End If
        bbl.UpdateMenu(ProgramID, RootName, Name, NeedControl, URL, GroupID, hiActulaUID.Value, QueryStringYN, dbName, ChnName, EngName, IsMenu, OrderByID, IsRoot, IsNewWin, Param, MenuType)
        e.Cancel = True
        gvMenu.EditIndex = -1 '取消編輯模式
        gvMenu.DataBind()
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        '新增一筆空白資料
        Dim bbl As OAMS.BBL.MenuBBL = New OAMS.BBL.MenuBBL()
        bbl.INSERT_NewOne(ddlRootName.SelectedValue, "", True, "", "", hiActulaUID.Value, dbName, True, True)
        gvMenu.PageIndex = 0
        gvMenu.EditIndex = 0
        gvMenu.DataBind()
    End Sub

    
    Protected Sub gvMenu_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenu.RowCommand
        If e.CommandName = "Select" Then '選定
            gvMenu.EditIndex = -1 '取消編輯模式   
            mpDetail.Show()
            gvMenuRights.Visible = True
        End If
        If e.CommandName = "Edit" Then

            gvMenuRights.Visible = False '右半方資料才秀出
        End If
    End Sub

    Protected Sub gvMenu_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvMenu.RowEditing
        gvMenu.SelectedIndex = -1 '取消
    End Sub

    Protected Sub gvMenuRights_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenuRights.RowCommand
        mpDetail.Show()
    End Sub

    Protected Sub ddlRootName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRootName.SelectedIndexChanged
        gvMenu.DataBind()
    End Sub
End Class
